import datetime
import os.path
import sys

from selenium import webdriver
from selenium.webdriver.ie.service import Service

from webdriver_manager.microsoft import EdgeChromiumDriverManager


class Edgedriver:
    options=''
    driver=''
    def __init__(self):
        self.options=webdriver.EdgeOptions()
        self.options.add_argument("normal")
        self.driver=webdriver.Edge(service=Service(EdgeChromiumDriverManager().install()),options=self.options)
        # 添加隐式等待，有些界面需要反应时间
        self.driver.implicitly_wait(2)
    # 截图
    # 以函数名+日期的方式命名
    def getscreen(self):
        dirname = datetime.datetime.now().strftime('%Y-%m-%d')
        if not os.path.exists("../images/" + dirname):
            os.mkdir("../images/" + dirname)
        filename = sys._getframe().f_back.f_code.co_name + "-" +datetime.datetime.now().strftime('%Y-%m-%d-%H%M%S') + ".png"
        self.driver.get_screenshot_as_file("../images/"+dirname+"/"+filename)


Blogdriver=Edgedriver()